{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 字典\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 创建字典的三种常见的方法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.直接按照字典的格式创建 ： {key1：value1，key2：value2，...} 2.dict()函数来创建字典： dict(key1=value1,key2=value2,...) 3.字典数据增加的方式：新建空字典 dict_name={},dict_name[key1]=value1...\n",
    "\n",
    "### 2.字典的性质"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu_10001': 'alex', 'stu_10002': 'jack', 'stu_10003': 'marry'}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 直接按照字典的格式创建 ： {key1：value1，key2：value2，...}\n",
    "stu_info = {\n",
    "    \"stu_10001\":\"alex\",\n",
    "    \"stu_10002\":\"jack\",\n",
    "    \"stu_10003\":\"marry\",\n",
    "           }\n",
    "stu_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu_10001': 'alex', 'stu_10002': 'jack', 'stu_10003': 'marry'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.dict()函数来创建字典： dict(key1=value1,key2=value2,...)\n",
    "stu_info1 = dict(\n",
    "    stu_10001 = \"alex\",\n",
    "    stu_10002 = \"jack\",\n",
    "    stu_10003 = \"marry\",\n",
    ")\n",
    "stu_info1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu_10001': 'alex', 'stu_10002': 'jack', 'stu_10003': 'marry'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info2 = {}\n",
    "stu_info2 [\"stu_10001\"] =\"alex\"\n",
    "stu_info2 [\"stu_10002\"] =\"jack\"\n",
    "stu_info2 [\"stu_10003\"] =\"marry\"\n",
    "stu_info2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['stu_10001', 'stu_10002', 'stu_10003'])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info2.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_values(['alex', 'jack', 'marry'])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_info2.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "dict_values(['alex', 'jack', 'marry'])\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
